package com.heima.freemarker.controller;

import com.heima.freemarker.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.HashMap;

@Controller
public class HelloController {
    @GetMapping("/basic")
    public String getModel(Model model){
        model.addAttribute("name", "哈哈嗨");
        Student student = new Student();
        student.setName("张三");
        student.setAge(30);
        model.addAttribute("stu",student);

        return "01-basic";
    }

    @GetMapping("/list")
    public String getList(Model model){
        HashMap<String, Student> map = new HashMap<>();
        Student student1 = new Student();
        student1.setMoney(100F);
        student1.setName("张三");
        student1.setAge(30);

        Student student2 = new Student();
        student2.setMoney(200F);
        student2.setName("李四");
        student2.setAge(10);
        ArrayList<Student> students = new ArrayList<>();
        students.add(student1);
        students.add(student2);
        map.put("stu1", student1);
        map.put("stu2", student2);
        model.addAttribute("stus", students);
        model.addAttribute("stuMap", map);
        return "02-list";
    }

    @GetMapping("/map")
    public String getMap(Model model){

        Student student1 = new Student();
        student1.setMoney(100F);
        student1.setName("张三");
        student1.setAge(30);

        Student student2 = new Student();
        student2.setMoney(200F);
        student2.setName("李四");
        student2.setAge(10);


        //model.addAttribute("stus", map);
        return "03-inner";
    }



}
